﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Configuration.Helper
{
    /// <summary>
    /// 位置助手
    /// </summary>
    public class LocationHelper
    {
        /// <summary>
        /// 计算两点的距离
        /// </summary>
        /// <param name="lat1"></param>
        /// <param name="lng1"></param>
        /// <param name="lat2"></param>
        /// <param name="lng2"></param>
        /// <returns></returns>
        public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
        {
            try
            {
                double distance = 0;
                double lonRes = 102900, latRes = 110000;
                distance = Math.Sqrt(Math.Abs(lat1 - lat2) * latRes * Math.Abs(lat1 - lat2) * latRes +
                                     Math.Abs(lng1 - lng2) * lonRes * Math.Abs(lng1 - lng2) * lonRes);
                //System.out.println( "两点间距离:" + distance );
                return distance;
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                throw;
            }

        }
    }
}
